<?php
/**
 * 老师同步云信
 */
namespace common\widgets;

class TeacherSyncAccount{
    /**
     * @param $teacherData
     * @return int|string
     * @author Lxs
     * 老师手机号码修改-同步云信
     */
    public static function synAccount($teacherData)
    {
        $AppKey = 'ff0f9a72db5b719dad88ce9dd23c16b7';
        $AppSecret = 'afcc2f923f42';

        $api = new NeteaseAPI($AppKey, $AppSecret, 'curl');
        $res = $api->createUserId($teacherData->mobile, 'miaoke');

        if($res['code'] == 200){
            $token = $res['info']['token'];
        }else{
            $update = $api->updateUserToken($teacherData->mobile);

            if($update['code'] == 200){
                $token =$update['info']['token'];
            }else{
                return $res['desc'];
            }
        }

        $chat_token = $token;
        $accessToken = $teacherData->mobile . $token;

        $teacherData->chat_token = $chat_token;
        $teacherData->accessToken = $accessToken;

        return $teacherData->save();
    }

}